<template>
  <div class="app-container">
    <vxe-split class="content" border vertical>
      <vxe-split-pane title="质检模板" height="50%">
        <vxe-grid
          ref="gridRef"
          v-bind="gridOptions"
          @toolbar-button-click="toolbarButtonClickEvent"
          @form-submit="formSubmitEvent"
          @form-reset="formResetEvent"
          @current-row-change="currentRowChangeEvent"
        >
          <template #active="{ row }">
            <vxe-button
              mode="text"
              status="primary"
              content="编辑"
              icon="vxe-icon-edit"
              @click="updateRow(row)"
            ></vxe-button>
            <vxe-button
              mode="text"
              status="primary"
              content="添加模板项"
              icon="vxe-icon-edit"
              @click="addProcedure(row)"
            ></vxe-button>
            <vxe-button
              mode="text"
              status="primary"
              content="模板下载"
              icon="vxe-icon-edit"
              @click="downloadTmp(row)"
            ></vxe-button>
            <vxe-button
              mode="text"
              status="primary"
              content="模板上传"
              icon="vxe-icon-edit"
              @click="uploadTmp(row)"
            ></vxe-button>
            <vxe-button
              mode="text"
              status="primary"
              content="删除"
              icon="vxe-icon-edit"
              @click="deleteData(row)"
            ></vxe-button>
          </template>
        </vxe-grid>
      </vxe-split-pane>
      <!--工序-->
      <vxe-split-pane height="50%">
        <vxe-grid
          ref="gridRef3"
          v-bind="gridOptions3"
          @toolbar-tool-click="toolbarToolClickEvent"
          @form-submit="formSubmitEvent"
          @form-reset="formResetEvent"
          @row-dragend="rowDragendEvent"
        >
          <template #active="{ row }">
            <vxe-button
              mode="text"
              status="primary"
              content="编辑"
              icon="vxe-icon-edit"
              @click="updateRow(row)"
            ></vxe-button>
            <vxe-button
              mode="text"
              status="primary"
              content="删除"
              icon="vxe-icon-edit"
              @click="deleteProcessRel(row)"
            ></vxe-button>
          </template>
        </vxe-grid>
      </vxe-split-pane>
    </vxe-split>

    <vxe-modal v-model="showPopup" v-bind="modalOptions" :loading="loading">
      <template #default>
        <vxe-form :data="formData" @submit="submitEvent" @reset="resetEvent">
          <vxe-form-item
            title="Id"
            field="name"
            span="24"
            :item-render="{}"
            :visible="false"
          >
            <template #default="params">
              <vxe-input
                v-model="formData.id"
                @change="changeEvent(params)"
              ></vxe-input>
            </template>
          </vxe-form-item>
          <vxe-form-item
            title="模板编码"
            field="code"
            span="24"
            :item-render="{}"
          >
            <template #default="params">
              <vxe-input
                v-model="formData.code"
                @change="changeEvent(params)"
              ></vxe-input>
            </template>
          </vxe-form-item>
          <vxe-form-item
            title="模板名称"
            field="name"
            span="24"
            :item-render="{}"
          >
            <template #default="params">
              <vxe-input
                v-model="formData.name"
                @change="changeEvent(params)"
              ></vxe-input>
            </template>
          </vxe-form-item>
          <vxe-form-item align="center" span="24" :item-render="{}">
            <template #default>
              <vxe-button
                type="submit"
                status="primary"
                content="提交"
              ></vxe-button>
              <vxe-button type="reset" content="重置"></vxe-button>
            </template>
          </vxe-form-item>
        </vxe-form>
      </template>
    </vxe-modal>

    <vxe-modal
      v-model="showPopup2"
      v-bind="modalOptions2"
      show-footer
      :loading="loading"
      show-confirm-button
      @confirm="confirmEvent"
    >
      <template #default>
        <vxe-grid
          ref="gridRef2"
          :confirm-closable="false"
          v-bind="gridOptions2"
          @toolbar-button-click="toolbarButtonClickEvent"
          @form-submit="formSubmitEvent"
          @form-reset="formResetEvent"
        >
        </vxe-grid>
      </template>
    </vxe-modal>
    <!--质检项目提交-->
    <vxe-modal
      v-model="showPopup4"
      v-bind="modalOptions4"
      show-footer
      :loading="loading"
      show-confirm-button
      @confirm="confirmEvent2"
    >
      <template #default>
        <vxe-grid
          ref="gridRef4"
          :confirm-closable="false"
          v-bind="gridOptions4"
          @toolbar-button-click="toolbarButtonClickEvent"
          @form-submit="formSubmitEvent"
          @form-reset="formResetEvent"
        >
        </vxe-grid>
      </template>
    </vxe-modal>

    <vxe-modal
      v-model="showPopup5"
      v-bind="modalOptions"
      show-confirm-button
      show-footer
      :loading="loading"
      @confirm="confirmEventUpload"
    >
      <template #default>
        <vxe-upload
          v-model="fileList"
          multiple
          :upload-method="uploadMethod"
        ></vxe-upload>
      </template>
    </vxe-modal>
  </div>
</template>

<script>
import {
  getProcessByPage,
  addProcess,
  delProcess,
} from "@/api/baseData/process";

import {
  getInspectionTemplateByPage,
  addInspectionTemplate,
  delInspectionTemplate,
  updateInspectionTmpFile,
} from "@/api/quality/inspectionTemplate";

import {
  getInspectionItemByPage,
  addInspectionItem,
  delInspectionItem,
} from "@/api/quality/inspectionItem";

import {
  getInspectionTemplateItemByPage,
  addInspectionTemplateItem,
  delInspectionTemplateItem,
  saveInspectionTemplateItem,
} from "@/api/quality/inspectionTemplateItem";

import {
  getProcessRelByPage,
  addProcessRel,
  delProcessRel,
  saveProcessSequence,
} from "@/api/baseData/processRel";

import {
  getMaterialByPage,
  addMaterial,
  delMaterial,
} from "@/api/baseData/material";
import {
  getProceduresByPage,
  addProcedures,
  delProcedures,
} from "@/api/baseData/procedures";
import {
  getInspectionTaskByPage,
  addInspectionTask,
  delInspectionTask,
  uploadFile,
} from "@/api/quality/inspectionTask";
import { VxeUI } from "vxe-pc-ui";

import { useRouter, useRoute } from "vue-router";
import { find } from "xe-utils";
const router = useRouter();
const findPageList = async (page) => {
  await getMaterialByPage(page);
  // return new Promise(resolve => {
  //   setTimeout(() => {
  //     resolve({
  //       result: list.slice((currentPage - 1) * pageSize, currentPage * pageSize),
  //       page: {
  //         total: list.length
  //       }
  //     })
  //   }, 100)
  // })
};
export default {
  data() {
    const gridOptions = {
      sortConfig: {
        remote: true,
      },
      rowConfig: {
        isCurrent: true,
        isHover: true,
      },
      loading: false,
      stripe: true,
      showOverflow: true,
      showFooter: true,
      height: "100%",
      columnConfig: {
        resizable: true,
        drag: true,
      },
      columnDragConfig: {
        trigger: "cell",
        showIcon: false,
        showGuidesStatus: true,
      },

      resizableConfig: {
        isDblclickAutoWidth: true,
      },
      pagerConfig: {
        total: 0,
        currentPage: 1,
        pageSize: 10,
      },
      toolbarConfig: {
        refresh: true,
        import: true,
        export: true,
        print: true,
        zoom: true,
        custom: true,
        buttons: [
          { name: "新增", code: "myAdd", status: "primary" },
          { name: "删除", code: "myDel", status: "error" },
          { name: "保存", code: "mySave", status: "success" },
        ],
      },
      formConfig: {
        data: {
          name: "",
          role: "",
          sex: "",
          num: "",
          address: "",
        },
        items: [
          {
            field: "name",
            title: "名称",
            span: 8,

            itemRender: { name: "VxeInput", props: { clearable: true } },
          },

          {
            field: "createTime",
            title: "时间",
            span: 8,

            itemRender: {
              name: "VxeDatePicker",
              props: {
                multiple: true,
              },
            },
          },

          {
            collapseNode: true,
            align: "right",
            span: 8,
            itemRender: {
              name: "VxeButtonGroup",
              options: [
                { type: "submit", content: "搜索", status: "primary" },
                { type: "reset", content: "重置" },
              ],
            },
          },
          {
            field: "createTime",
            title: "时间",
            span: 8,
            folding: true,
            itemRender: {
              name: "VxeDatePicker",
              props: {
                multiple: true,
              },
            },
          },
        ],
      },
      columns: [
        { field: "seq", type: "seq", width: 70 },

        { field: "code", title: "模板编码", sortable: true, width: 180 },
        {
          field: "name",
          title: "模板名称",
          sortable: true,
          width: 180,
        },

        {
          field: "version",
          title: "版本",
          sortable: true,
          width: 180,
        },
        { field: "createTime", title: "创建时间", width: 180 },
        {
          field: "active",
          title: "操作",
          fixed: "right",
          width: 500,
          slots: { default: "active" },
        },
      ],
      scrollX: {
        gt: 0,
        enabled: true,
      },
      scrollY: {
        gt: 0,
        enabled: true,
      },
      proxyConfig: {
        // props: {
        //   result: 'result', // 配置响应结果列表字段
        //   total: 'page.total' // 配置响应结果总页数字段
        // },

        sort: true,
        form: true,
        ajax: {
          query: async ({ page, sorts, form }) => {
            console.log(page, sorts, form, "----");
            // 默认接收 Promise<{ result: [], page: { total: 100 } }>
            let result = await getInspectionTemplateByPage({
              ...page,
            });
            return {
              result: result.data.records,
              page: {
                total: result.data.total,
              },
            };
          },
        },
      },
    };
    const gridOptions2 = {
      sortConfig: {
        remote: true,
      },
      height: "100%",
      loading: false,
      stripe: true,
      showOverflow: true,
      showFooter: true,

      columnConfig: {
        resizable: true,
        drag: true,
      },
      columnDragConfig: {
        trigger: "cell",
        showIcon: false,
        showGuidesStatus: true,
      },
      rowConfig: {
        isHover: true,
      },
      resizableConfig: {
        isDblclickAutoWidth: true,
      },
      pagerConfig: {
        total: 0,
        currentPage: 1,
        pageSize: 10,
      },
      toolbarConfig: {
        refresh: true,
        import: true,
        export: true,
        print: true,
        zoom: true,
        custom: true,
        buttons: [
          { name: "新增", code: "myAdd", status: "primary" },
          { name: "删除", code: "myDel", status: "error" },
          { name: "保存", code: "mySave", status: "success" },
        ],
      },
      formConfig: {
        data: {
          name: "",
          role: "",
          sex: "",
          num: "",
          address: "",
        },
        items: [
          {
            field: "name",
            title: "名称",
            span: 8,

            itemRender: { name: "VxeInput", props: { clearable: true } },
          },

          {
            field: "createTime",
            title: "时间",
            span: 8,

            itemRender: {
              name: "VxeDatePicker",
              props: {
                multiple: true,
              },
            },
          },

          {
            collapseNode: true,
            align: "right",
            span: 8,
            itemRender: {
              name: "VxeButtonGroup",
              options: [
                { type: "submit", content: "搜索", status: "primary" },
                { type: "reset", content: "重置" },
              ],
            },
          },
          {
            field: "createTime",
            title: "时间",
            span: 8,
            folding: true,
            itemRender: {
              name: "VxeDatePicker",
              props: {
                multiple: true,
              },
            },
          },
        ],
      },
      columns: [
        { type: "checkbox", width: 60 },
        { field: "seq", type: "seq", width: 70 },
        { field: "code", title: "物料代码", sortable: true, width: 180 },
        {
          field: "name",
          title: "物料名称",
          sortable: true,
          width: 180,
        },
        {
          field: "memo",
          title: "物料描述",
          sortable: true,
          width: 180,
        },

        {
          field: "materialTypeName",
          title: "物料分类描述",
          sortable: true,
          width: 180,
        },
        {
          field: "unit",
          title: "单位",
          sortable: true,
          width: 180,
        },
        {
          field: "maturingTime",
          title: "熟化时间",
          sortable: true,
          width: 180,
        },
        {
          field: "testTime",
          title: "测试时间",
          sortable: true,
          width: 180,
        },
        { field: "createTime", title: "创建时间", width: 180 },
        {
          field: "active",
          title: "操作",
          fixed: "right",
          width: 200,
          slots: { default: "active" },
        },
      ],
      scrollX: {
        gt: 0,
        enabled: true,
      },
      scrollY: {
        gt: 0,
        enabled: true,
      },
      proxyConfig: {
        // props: {
        //   result: 'result', // 配置响应结果列表字段
        //   total: 'page.total' // 配置响应结果总页数字段
        // },

        sort: true,
        form: true,
        ajax: {
          query: async ({ page, sorts, form }) => {
            console.log(page, sorts, form, "----");
            // 默认接收 Promise<{ result: [], page: { total: 100 } }>
            let result = await getMaterialByPage({
              ...page,
            });
            return {
              result: result.data.records,
              page: {
                total: result.data.total,
              },
            };
          },
        },
      },
    };
    const gridOptions3 = {
      sortConfig: {
        remote: true,
      },
      loading: false,
      stripe: true,
      showOverflow: true,
      showFooter: true,
      height: "100%",
      columnConfig: {
        resizable: true,
        drag: true,
      },
      columnDragConfig: {
        trigger: "cell",
        showIcon: false,
        showGuidesStatus: true,
      },
      rowConfig: {
        isHover: true,
        drag: true,
      },
      resizableConfig: {
        isDblclickAutoWidth: true,
      },
      toolbarConfig: {
        tools: [
          { name: "查询", code: "mySearch", status: "primary" },
          // { name: "删除", code: "del", status: "error" },
          { name: "保存顺序", code: "mySave", status: "success" },
        ],
      },
      pagerConfig: {
        total: 0,
        currentPage: 1,
        pageSize: 10,
      },
      // toolbarConfig: {
      //   refresh: true,
      //   import: true,
      //   export: true,
      //   print: true,
      //   zoom: true,
      //   custom: true,
      //   buttons: [
      //     { name: "新增", code: "myAdd", status: "primary" },
      //     { name: "删除", code: "myDel", status: "error" },
      //     { name: "保存", code: "mySave", status: "success" },
      //   ],
      // },
      // formConfig: {
      //   data: {
      //     name: "",
      //     role: "",
      //     sex: "",
      //     num: "",
      //     address: "",
      //   },
      //   items: [
      //     {
      //       field: "name",
      //       title: "名称",
      //       span: 8,

      //       itemRender: { name: "VxeInput" },
      //     },

      //     {
      //       field: "createTime",
      //       title: "时间",
      //       span: 8,

      //       itemRender: {
      //         name: "VxeDatePicker",
      //         props: {
      //           multiple: true,
      //         },
      //       },
      //     },

      //     {
      //       collapseNode: true,
      //       align: "right",
      //       span: 8,
      //       itemRender: {
      //         name: "VxeButtonGroup",
      //         options: [
      //           { type: "submit", content: "搜索", status: "primary" },
      //           { type: "reset", content: "重置" },
      //         ],
      //       },
      //     },
      //     {
      //       field: "createTime",
      //       title: "时间",
      //       span: 8,
      //       folding: true,
      //       itemRender: {
      //         name: "VxeDatePicker",
      //         props: {
      //           multiple: true,
      //         },
      //       },
      //     },
      //   ],
      // },
      columns: [
        { type: "checkbox", width: 60 },
        { field: "seq", type: "seq", width: 70 },
        {
          field: "templateName",
          title: "模板名称",
          sortable: true,
          width: 180,
        },
        {
          field: "itemName",
          title: "项名称",
          sortable: true,
          width: 180,
          dragSort: true,
        },
        {
          field: "fillType",
          title: "检验类型",
          sortable: true,
          width: 180,
          // dragSort: true,
        },
        {
          field: "sequence",
          title: "质检项顺序",
          sortable: true,
          width: 180,
        },
        { field: "createTime", title: "创建时间", width: 180 },
        {
          field: "active",
          title: "操作",
          fixed: "right",
          width: 200,
          slots: { default: "active" },
        },
      ],
      scrollX: {
        gt: 0,
        enabled: true,
      },
      scrollY: {
        gt: 0,
        enabled: true,
      },
      proxyConfig: {
        // props: {
        //   result: 'result', // 配置响应结果列表字段
        //   total: 'page.total' // 配置响应结果总页数字段
        // },

        sort: true,
        // form: true,
        ajax: {
          query: async ({ page, sorts, form }) => {
            console.log(page, sorts, form, "----");
            // 默认接收 Promise<{ result: [], page: { total: 100 } }>
            let result = await getInspectionTemplateItemByPage({
              ...page,
              inspectionTemplateId: this.processRowData.id,
            });
            return {
              result: result.data.records,
              page: {
                total: result.data.total,
              },
            };
          },
        },
      },
    };
    const gridOptions4 = {
      sortConfig: {
        remote: true,
      },
      loading: false,
      stripe: true,
      showOverflow: true,
      showFooter: true,
      height: "100%",
      columnConfig: {
        resizable: true,
        drag: true,
      },
      columnDragConfig: {
        trigger: "cell",
        showIcon: false,
        showGuidesStatus: true,
      },
      rowConfig: {
        isHover: true,
      },
      resizableConfig: {
        isDblclickAutoWidth: true,
      },
      pagerConfig: {
        total: 0,
        currentPage: 1,
        pageSize: 10,
      },
      toolbarConfig: {
        refresh: true,
        import: true,
        export: true,
        print: true,
        zoom: true,
        custom: true,
        buttons: [
          { name: "新增", code: "myAdd", status: "primary" },
          { name: "删除", code: "myDel", status: "error" },
          { name: "保存", code: "mySave", status: "success" },
        ],
      },
      formConfig: {
        data: {
          name: "",
          role: "",
          sex: "",
          num: "",
          address: "",
        },
        items: [
          {
            field: "name",
            title: "名称",
            span: 8,

            itemRender: { name: "VxeInput", props: { clearable: true } },
          },

          {
            field: "createTime",
            title: "时间",
            span: 8,

            itemRender: {
              name: "VxeDatePicker",
              props: {
                multiple: true,
              },
            },
          },

          {
            collapseNode: true,
            align: "right",
            span: 8,
            itemRender: {
              name: "VxeButtonGroup",
              options: [
                { type: "submit", content: "搜索", status: "primary" },
                { type: "reset", content: "重置" },
              ],
            },
          },
          {
            field: "createTime",
            title: "时间",
            span: 8,
            folding: true,
            itemRender: {
              name: "VxeDatePicker",
              props: {
                multiple: true,
              },
            },
          },
        ],
      },
      columns: [
        { type: "checkbox", width: 60 },
        { field: "seq", type: "seq", width: 70 },
        { field: "code", title: "编码", sortable: true, width: 180 },
        {
          field: "name",
          title: "名称",
          sortable: true,
          width: 180,
        },
        {
          field: "fillType",
          title: "检验类型",
          sortable: true,
          width: 180,
        },
        // {
        //   field: "describe",
        //   title: "名称",
        //   sortable: true,
        //   width: 180,
        // },
        {
          field: "standTime",
          title: "标准工时(分)",
          sortable: true,
          width: 180,
        },
        {
          field: "prepareTime",
          title: "准备工时(分)",
          sortable: true,
          width: 180,
        },
        {
          field: "transferTime",
          title: "转移工时(分)",
          sortable: true,
          width: 180,
        },
        { field: "createTime", title: "创建时间", width: 180 },
        {
          field: "active",
          title: "操作",
          fixed: "right",
          width: 200,
          slots: { default: "active" },
        },
      ],
      scrollX: {
        gt: 0,
        enabled: true,
      },
      scrollY: {
        gt: 0,
        enabled: true,
      },
      proxyConfig: {
        // props: {
        //   result: 'result', // 配置响应结果列表字段
        //   total: 'page.total' // 配置响应结果总页数字段
        // },

        sort: true,
        form: true,
        ajax: {
          query: async ({ page, sorts, form }) => {
            console.log(page, sorts, form, "----");
            // 默认接收 Promise<{ result: [], page: { total: 100 } }>
            let result = await getInspectionItemByPage({
              ...page,
            });
            return {
              result: result.data.records,
              page: {
                total: result.data.total,
              },
            };
          },
        },
      },
    };
    const showPopup = false;
    const showPopup5 = false;
    const modalOptions2 = {
      title: "在弹窗中使用表单",
      width: "80%",
      height: 600,
      escClosable: true,
      // resize: true,
      // showMaximize: true,
      //禁止拖动
      draggable: true,
    };
    const modalOptions4 = {
      title: "在弹窗中使用表单",
      width: "80%",
      height: 600,
      escClosable: true,
      // resize: true,
      // showMaximize: true,
      //禁止拖动
      draggable: true,
    };
    const modalOptions = {
      title: "在弹窗中使用表单",
      width: 800,

      escClosable: true,
      resize: true,
      showMaximize: true,
      //禁止拖动
      draggable: true,
    };
    const sexItemRender = {
      name: "VxeSelect",
      options: [
        { label: "女", value: "Women" },
        { label: "男", value: "Man" },
      ],
    };
    const formOptions = {
      data: {
        name: "",
        role: "",
        sex: "",
        age: "",
        address: "",
      },
      rules: {
        name: [{ required: true, message: "名称必填" }],
        // role: [{ required: true, message: "角色必填" }],
        // sex: [{ required: true, message: "性别必选" }],
        // age: [
        //   { required: true, message: "年龄必填" },
        //   { type: "number", min: 18, max: 46, message: "年龄范围18~46" },
        // ],
      },
      items: [
        {
          field: "code",
          title: "编码",
          span: 24,
          itemRender: { name: "VxeInput" },
        },
        {
          field: "name",
          title: "名称",
          span: 24,
          itemRender: { name: "VxeInput" },
        },
        // {
        //   field: "role",
        //   title: "角色",
        //   span: 24,
        //   itemRender: { name: "VxeInput" },
        // },
        // { field: "sex", title: "性别", span: 12, itemRender: sexItemRender },
        // {
        //   field: "age",
        //   title: "年龄",
        //   span: 12,
        //   itemRender: { name: "VxeNumberInput", props: { type: "integer" } },
        // },
        // {
        //   field: "address",
        //   title: "地址",
        //   span: 24,
        //   itemRender: { name: "VxeTextarea" },
        // },
        {
          align: "center",
          span: 24,
          itemRender: {
            name: "VxeButtonGroup",
            options: [
              { type: "submit", content: "提交", status: "primary" },
              { type: "reset", content: "重置" },
            ],
          },
        },
      ],
    };
    const formData = {
      id: 0,
      code: "",
      name: "",
      processDesc: "",
      version: "",
      materialId: "",
      materialName: "",
    };
    const fileList = [];
    const uploadMethod = async ({ file }) => {
      const formData = new FormData();
      formData.append("file", file);
      let result = await uploadFile(formData);
      this.processRowData.filePath = result.data.url;
      this.processRowData.fileName = result.data.name;
      console.log(result, "===>result===>");
      console.log(this.fileList, "====>result===>");
    };
    return {
      gridOptions,
      showPopup,
      modalOptions,
      sexItemRender,
      formOptions,
      loading: false,
      formData,
      showPopup2: false,
      showPopup4: false,
      showPopup5: false,
      gridOptions2,
      gridOptions3,
      gridOptions4,
      modalOptions2,
      modalOptions4,
      fileList,
      processRowData: { id: 0, filePath: "", fileName: "" },
      uploadMethod,
    };
  },
  methods: {
    toolbarButtonClickEvent(params) {
      if (params.code == "myAdd") {
        this.showPopup = true;
      }
      // console.log(this.$refs.gridRef3.getFullData());
    },
    async toolbarToolClickEvent(params) {
      if (params.code == "mySave") {
        this.$refs.gridRef.getFullData();
        console.log(this.$refs.gridRef3.getFullData());
        await saveInspectionTemplateItem(this.$refs.gridRef3.getFullData());
        const $grid = this.$refs.gridRef3.commitProxy("reload");
      } else if (params.code == "mySearch") {
        const $grid = this.$refs.gridRef3.commitProxy("reload");
      }
      // console.log(this.$refs.gridRef3.getFullData());
    },
    //删选勾选
    formSubmitEvent() {
      console.log("form submit");
    },
    formResetEvent() {
      console.log("form reset");
    },
    //表单的提交
    async submitEvent() {
      this.loading = true;
      await addInspectionTemplate(this.formData);

      const $grid = this.$refs.gridRef.commitProxy("reload");
      VxeUI.modal.message({ content: "保存成功", status: "success" });
      this.loading = false;
      this.showPopup = false;
    },
    //表单的重置
    resetEvent() {
      console.log("重置事件");
    },
    updateRow(row) {
      this.formOptions.data = row;
      this.showPopup = true;
      console.log(row.id, "---row---");
    },
    async deploy(row) {
      this.formOptions.data = row;
      console.log(row.id, "---row---");
      await camundaModelDeploymentById(row);
    },
    addProcedure(row) {
      this.showPopup4 = true;
      this.processRowData = row;
      console.log(row, "---row---");
    },
    designRow(row) {
      this.$router.push({
        path: "/flowable/bpmtest",
        query: {
          id: row.id,
        },
      });

      console.log(row.id, "---row---");
    },
    onClick(row) {
      this.showPopup2 = true;
      // const selectKeys = this.$refs.gridRef.getCheckboxRecords();
      // console.log(selectKeys, "---row---");
    },
    confirmEvent() {
      const selectKeys = this.$refs.gridRef2.getCheckboxRecords();
      console.log(selectKeys, "---selectKeys---");
      this.formData.materialId = selectKeys[0].id;
      this.formData.materialName = selectKeys[0].name;
    },
    //添加工序提交
    async confirmEvent2() {
      const selectKeys = this.$refs.gridRef4.getCheckboxRecords();
      try {
        const result = await addInspectionTemplateItem({
          inspectionTemplateId: this.processRowData.id,
          inspectionItemIds: selectKeys.map((item) => item.id),
        });
      } catch (error) {
      } finally {
        const selectKeys = this.$refs.gridRef3.commitProxy("reload");
        console.log(selectKeys, this.processRowData, "---selectKeys---");
      }
    },
    async deleteData(row) {
      await delProcess({ id: row.id });
      const $grid = this.$refs.gridRef.commitProxy("reload");
      VxeUI.modal.message({ content: "删除成功", status: "success" });
    },
    async deleteProcessRel(row) {
      try {
        await delInspectionTemplateItem({ id: row.id });
        VxeUI.modal.message({ content: "删除成功", status: "success" });
      } catch (error) {
      } finally {
        const $grid = this.$refs.gridRef3.commitProxy("reload");
      }
    },
    currentRowChangeEvent({ row }) {
      this.processRowData = row;
      console.log(row);
      const $grid = this.$refs.gridRef3.commitProxy("reload");
    },
    rowDragendEvent({ newRow, oldRow, dragPos }) {
      // console.log(
      //   `拖拽完成，被拖拽行：${oldRow.id} 目标行：${newRow.id} 目标位置：${dragPos}`
      // );
      // const $grid = this.$refs.gridRef3;
      // if ($grid) {
      //   const tableData = $grid3.getTableData();
      //   console.log(tableData);
      // }
    },
    downloadTmp(row) {
      fetch(row.filePath)
        .then((response) => response.blob())
        .then((blob) => {
          VxeUI.saveFile({
            filename: row.fileName,
            content: blob,
          });
        });
    },
    uploadTmp(row) {
      this.showPopup5 = true;
      this.processRowData = row;
    },
    async confirmEventUpload() {
      await updateInspectionTmpFile({ ...this.processRowData });
      const $grid = this.$refs.gridRef.commitProxy("reload");
    },
  },
};
</script>
<style lang="scss" scoped>
.content {
  height: calc(100vh - 130px);
}
</style>
